<template>
	<view :style="viewColor">
		<view class="community_type_list">
			<view class="add_community_button" @click="addCommunityButton(1)">发布服务</view>
			<view class="add_community_button" @click="addCommunityButton(2)">发布视频</view>
			<view class="add_community_button" @click="addCommunityButton(3)">发布需求</view>
		</view>
		<authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize>
		<view class="foot" v-if="newData.status && newData.status.status">
			<view class="page-footer" id="target" :style="{'background-color':newData.bgColor.color[0].item}">
				<view class="foot-item" v-for="(item,index) in newData.menuList" :key="index"
					@click="goRouter(item)">
					<block v-if="index != 2">
						<block v-if="item.link == activeRouter">
							<image :src="item.imgList[0]"></image>
							<view class="txt" :style="{color:newData.activeTxtColor.color[0].item}">{{item.name}}
							</view>
						</block>
						<block v-else>
							<image :src="item.imgList[1]"></image>
							<view class="txt" :style="{color:newData.txtColor.color[0].item}">{{item.name}}</view>
						</block>
					</block>
					<block v-else>
						<image class="foot-item-add" :src="item.imgList[0]"></image>
					</block>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { getUserInfo, userPerm } from '@/api/user.js';
	import { mapGetters } from "vuex";
	import { configMap } from "@/utils";
	import parser from "@/components/jyf-parser/jyf-parser";
	import authorize from '@/components/Authorize';
	import { HTTP_REQUEST_URL } from '@/config/app';
	import { getNavigation } from '@/api/public.js';
	const app = getApp();
	export default {
		components: {
			"jyf-parser": parser,
			authorize,
		},
		data() {
			return {
				isAuto: false, //没有授权的不会自动授权
				isShowAuth: false, //是否隐藏授权
				domain: HTTP_REQUEST_URL,
				newData: {},
				userInfo: {},
			};
		},
		beforeDestroy() {
		},
		computed: {...configMap({sys_intention_agree:''},mapGetters(['isLogin','viewColor','keyColor']))
		},
		onLoad(options) {
			if (this.isLogin) {
				this.getUserInfo();
			} else {
				this.isAuto = true;
				this.isShowAuth = true
			}
		},
		onShow() {
			this.getNav()
		},
		onReady() {},
		methods: {
			goRouter(item) {
				var pages = getCurrentPages();
				var page = (pages[pages.length - 1]).$page.fullPath;
				if (item.link == page) return
				uni.switchTab({
					url: item.link,
					fail(err) {
						uni.redirectTo({
							url: item.link
						})
					}
				})
			},
			/**
			 * 获取个人用户信息
			 */
			getUserInfo: function() {
				let that = this;
				getUserInfo().then(res => {
					that.userInfo = res.data;
				});
			},
			addCommunityButton(type) {
				let that = this
				if(!that.isLogin){
					that.isAuto = true;
					that.isShowAuth = true
					return false;
				}
				let url = '/pages/plantGrass/plant_release/index?type='+type;
				if(type ==1) {
					userPerm({type:1}).then(res=>{
						if(!res.data.is_perm) {
							return uni.showModal({
								title: '温馨提示',
								content: '每个用户每月只限免费发布3次，想要发布更多请选择开通VIP？',
								success: function (res) {
									if (res.confirm) {
										return that.$util.Tips('/pages/annex/vip_paid/index');
									} else if (res.cancel) {
										console.log('用户点击取消');
									}
								}
							});
						}else{
							that.$util.Tips(url)
						}
					})
				} else {
					that.$util.Tips(url)
				}
			},
			// 授权回调
			onLoadFun: function() {
				this.isShowAuth = false;
				return uni.switchTab({
					url: '/pages/user/index'
				});
			},
			// 授权关闭
			authColse: function(e) {
				this.isShowAuth = e
			},
			getNav(){
				getNavigation().then(res => {
					this.newData = res.data
					if (this.newData.status && this.newData.status.status) {
						uni.hideTabBar()
					} else {
						uni.showTabBar()
					}
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.community_type_list {
		width: 690rpx;
		margin: 200rpx auto;
		text-align: center;
		.add_community_button {
			background: var(--view-theme);
			padding: 30rpx;
			font-size: 35rpx;
			font-weight: bold;
			margin-bottom: 20rpx;
		}
	}
	.page-footer {
		position: fixed;
		bottom: 0;
		z-index: 30;
		display: flex;
		align-items: center;
		justify-content: space-around;
		width: 100%;
		height: 98rpx;
	height: calc(98rpx + constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
		height: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
		box-sizing: border-box;
		border-top: 1px solid #F3F3F3;
		background-color: #fff;
		box-shadow: 0px 0px 17rpx 1rpx rgba(206, 206, 206, 0.32);
		padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
		padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
		&.filter{
			filter: blur(2rpx);
		}
		.foot-item {
			display: flex;
			width: max-content;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			position: relative;
			.count-num {
				position: absolute;
				display: flex;
				justify-content: center;
				align-items: center;
				width: 40rpx;
				height: 40rpx;
				top: 0rpx;
				right: -15rpx;
				color: #fff;
				font-size: 20rpx;
				background-color: #FD502F;
				border-radius: 50%;
				padding: 4rpx;
			}
		}
		.foot-item image {
			height: 50rpx;
			width: 50rpx;
			text-align: center;
			margin: 0 auto;
		}
		.foot-item .foot-item-add {
			width: 100rpx;
			height: 100rpx;
			margin-bottom: 70rpx;
		}
		.foot-item .txt {
			font-size: 24rpx;
		}
	}
</style>